

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/deng-2022/blog_2/img/fluid.png">
  <link rel="icon" href="/deng-2022/blog_2/img/icon/dw.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Memory">
  <meta name="keywords" content="">
  
    <meta name="description" content="逐步引导你掌握Git常用操作和工作流程">
<meta property="og:type" content="article">
<meta property="og:title" content="入门指南：掌握Git的基本操作及进阶学习">
<meta property="og:url" content="https://atomgit.com/deng-2022/blog_2/2023/03/17/%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97%EF%BC%9A%E6%8E%8C%E6%8F%A1Git%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C%E5%8F%8A%E8%BF%9B%E9%98%B6%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="Memory&#39;s blog">
<meta property="og:description" content="逐步引导你掌握Git常用操作和工作流程">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://atomgit.com/deng-2022/blog_2/img/artical/sky5.jpg">
<meta property="article:published_time" content="2023-03-16T16:24:49.000Z">
<meta property="article:modified_time" content="2023-11-13T00:47:09.000Z">
<meta property="article:author" content="Memory">
<meta property="article:tag" content="经验">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://atomgit.com/deng-2022/blog_2/img/artical/sky5.jpg">
  
  
  
  <title>入门指南：掌握Git的基本操作及进阶学习 - Memory&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/deng-2022/blog_2/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/deng-2022/blog_2/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/deng-2022/blog_2/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"atomgit.com","root":"/deng-2022/blog_2/","version":"1.9.4","typing":{"enable":true,"typeSpeed":100,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":false,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/deng-2022/blog_2/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/deng-2022/blog_2/js/utils.js" ></script>
  <script  src="/deng-2022/blog_2/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 75vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/deng-2022/blog_2/">
      <strong>Memory&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/deng-2022/blog_2/img/newBG/girl.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="入门指南：掌握Git的基本操作及进阶学习"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Memory
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-03-17 00:24" pubdate>
          2023年3月17日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          1.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          5 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="Git"
        id="heading-0bcc70105ad279503e31fe7b3f47b665" role="tab" data-toggle="collapse" href="#collapse-0bcc70105ad279503e31fe7b3f47b665"
        aria-expanded="true"
      >
        Git
        <span class="list-group-count">(2)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-0bcc70105ad279503e31fe7b3f47b665"
           role="tabpanel" aria-labelledby="heading-0bcc70105ad279503e31fe7b3f47b665">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="经验"
        id="heading-32a8e000e928e6dc255876d9fc0178b3" role="tab" data-toggle="collapse" href="#collapse-32a8e000e928e6dc255876d9fc0178b3"
        aria-expanded="true"
      >
        经验
        <span class="list-group-count">(2)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-32a8e000e928e6dc255876d9fc0178b3"
           role="tabpanel" aria-labelledby="heading-32a8e000e928e6dc255876d9fc0178b3">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/deng-2022/blog_2/2023/03/17/%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97%EF%BC%9A%E6%8E%8C%E6%8F%A1Git%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C%E5%8F%8A%E8%BF%9B%E9%98%B6%E5%AD%A6%E4%B9%A0/" title="入门指南：掌握Git的基本操作及进阶学习"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">入门指南：掌握Git的基本操作及进阶学习</span>
        </a>
      
    
      
      
        <a href="/deng-2022/blog_2/2023/07/15/%E8%A7%A3%E5%86%B3%20Git%20%E8%BF%9C%E7%A8%8B%E6%8E%A8%E9%80%81%E6%8A%A5%E9%94%99%E7%9A%84%E7%BB%88%E6%9E%81%E6%8C%87%E5%8D%97/" title="解决 Git 远程推送报错的终极指南"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">解决 Git 远程推送报错的终极指南</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
        
      </div>
    </div>
  
</div>


  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">入门指南：掌握Git的基本操作及进阶学习</h1>
            
              <p class="note note-success">
                
                  
                    本文最后更新于：7 个月前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="导言"><a href="#导言" class="headerlink" title="导言"></a>导言</h1><ul>
<li><h5 id="Git-是一个分布式版本控制工具，提供代码托管服务"><a href="#Git-是一个分布式版本控制工具，提供代码托管服务" class="headerlink" title="Git 是一个分布式版本控制工具，提供代码托管服务"></a>Git 是一个分布式版本控制工具，提供代码托管服务</h5></li>
</ul>
<blockquote>
<p>🔥 推荐阅读：<a target="_blank" rel="noopener" href="https://juejin.cn/post/7296801242793033754">git 大厂代码提交原则（适用新手，细节拉满） - 掘金 (juejin.cn)</a></p>
</blockquote>
<h2 id="基础"><a href="#基础" class="headerlink" title="基础"></a>基础</h2><h3 id="工作区状态"><a href="#工作区状态" class="headerlink" title="工作区状态"></a>工作区状态</h3><ul>
<li><h5 id="工作区：包含-git-隐藏文件夹的目录，也称为工作目录，用于存放开发的代码"><a href="#工作区：包含-git-隐藏文件夹的目录，也称为工作目录，用于存放开发的代码" class="headerlink" title="工作区：包含.git 隐藏文件夹的目录，也称为工作目录，用于存放开发的代码"></a>工作区：包含.git 隐藏文件夹的目录，也称为工作目录，用于存放开发的代码</h5></li>
</ul>
<ul>
<li><h5 id="版本库：-git-隐藏文件夹，储存配置信息、日志信息和文件版本信息等"><a href="#版本库：-git-隐藏文件夹，储存配置信息、日志信息和文件版本信息等" class="headerlink" title="版本库：.git 隐藏文件夹，储存配置信息、日志信息和文件版本信息等"></a>版本库：.git 隐藏文件夹，储存配置信息、日志信息和文件版本信息等</h5></li>
</ul>
<ul>
<li><h5 id="暂存区：-git-隐藏文件夹中的一个-index-文件，也可叫做-stage，用来临时保存修改文件"><a href="#暂存区：-git-隐藏文件夹中的一个-index-文件，也可叫做-stage，用来临时保存修改文件" class="headerlink" title="暂存区：.git 隐藏文件夹中的一个 index 文件，也可叫做 stage，用来临时保存修改文件"></a>暂存区：.git 隐藏文件夹中的一个 index 文件，也可叫做 stage，用来临时保存修改文件</h5></li>
</ul>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs markdown">（1）untracked 未跟踪（未被纳入版本控制）<br>（2）tracked 已跟踪（被纳入版本控制）<br><span class="hljs-code">	1）Unmodified 未修改状态</span><br><span class="hljs-code">	2）Modified 已修改状态</span><br><span class="hljs-code">	3）Staged 已暂存状态</span><br></code></pre></td></tr></table></figure>

<h3 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h3><h4 id="全局设置："><a href="#全局设置：" class="headerlink" title="全局设置："></a>全局设置：</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs c">git config --global user.name <span class="hljs-string">&quot;用户名</span><br><span class="hljs-string">git config --global user.email &quot;</span>用户邮箱<span class="hljs-string">&quot;</span><br></code></pre></td></tr></table></figure>

<h4 id="获取-Git-仓库："><a href="#获取-Git-仓库：" class="headerlink" title="获取 Git 仓库："></a>获取 Git 仓库：</h4><p> 在本地初始化一个仓库：git init<br>​ 从远处仓库克隆：git clone 【仓库地址(URL)】</p>
<h4 id="本地仓库-工作区-常用命令："><a href="#本地仓库-工作区-常用命令：" class="headerlink" title="本地仓库(工作区)常用命令："></a>本地仓库(工作区)常用命令：</h4><ul>
<li>查看工作区内的文件状态（是否纳入版本控制？已纳入的是否修改？修改后的是否暂存？）</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git status<br></code></pre></td></tr></table></figure>

<ul>
<li>将文件的修改加入暂存区</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git add 【文件名】<br></code></pre></td></tr></table></figure>

<ul>
<li>将暂存区的文件取消暂存或者切换到指定版本 2</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git reset【版本号】<br></code></pre></td></tr></table></figure>

<ul>
<li>将暂存区的文件提交修改到版本库</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git commit -m 【修改信息】【文件名】<br></code></pre></td></tr></table></figure>

<ul>
<li>查看日志，查看提交记录，方便回溯到指定版本</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git <span class="hljs-built_in">log</span><br></code></pre></td></tr></table></figure>

<h4 id="远程仓库-工作区-常用命令："><a href="#远程仓库-工作区-常用命令：" class="headerlink" title="远程仓库(工作区)常用命令："></a>远程仓库(工作区)常用命令：</h4><ul>
<li>查看远程仓库：查看仓库名、仓库地址(URL)</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git remote -v<br></code></pre></td></tr></table></figure>

<ul>
<li>将本地仓库与远程仓库连接起来</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs c">git remote add 【仓库名】【仓库地址】<br>git remote add origin【仓库地址(URL)】<br></code></pre></td></tr></table></figure>

<ul>
<li>从远程仓库克隆</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git clone 【仓库地址(URL)】<br></code></pre></td></tr></table></figure>

<ul>
<li>从远程仓库拉取</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs c">git pull 【仓库名】【仓库分支】<br>git pull origin master<br></code></pre></td></tr></table></figure>

<ul>
<li>将工作区内的文件推送/上传到远程仓库的分支上（文件一定是成功提交到版本库中的，才能推送至远程仓库）</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs c">git push【仓库名】【仓库分支】<br>git push origin master<br></code></pre></td></tr></table></figure>

<h4 id="分支操作"><a href="#分支操作" class="headerlink" title="分支操作"></a>分支操作</h4><ul>
<li>列出所有本地分支</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git branch<br></code></pre></td></tr></table></figure>

<ul>
<li>列出所有远程分支</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git branch -r<br></code></pre></td></tr></table></figure>

<ul>
<li>列出所有本地分支和远程分支</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git branch -a<br></code></pre></td></tr></table></figure>

<ul>
<li>在本地创建分支</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git branch 【分支名】<br></code></pre></td></tr></table></figure>

<ul>
<li>切换本地分支</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git checkout 【分支名】<br></code></pre></td></tr></table></figure>

<ul>
<li>将该本地分支推送至远程分支</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git push 【仓库名】【分支名】<br></code></pre></td></tr></table></figure>

<ul>
<li>在该分支下，合并指定分支</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git merge 【分支名】<br></code></pre></td></tr></table></figure>

<h4 id="标签操作"><a href="#标签操作" class="headerlink" title="标签操作"></a>标签操作</h4><ul>
<li>列出已有标签</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git tag<br></code></pre></td></tr></table></figure>

<ul>
<li>创建标签</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git tag 【标签名】<br></code></pre></td></tr></table></figure>

<ul>
<li>将标签推送至远程仓库</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git push 【仓库名】【标签名】<br></code></pre></td></tr></table></figure>

<ul>
<li>检出标签</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git checkout -b 【分支名】【标签名】<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="分支：开发隔离-，标签：分支下的版本控制"><a href="#分支：开发隔离-，标签：分支下的版本控制" class="headerlink" title="分支：开发隔离 ，标签：分支下的版本控制"></a>分支：开发隔离 ，标签：分支下的版本控制</h5></li>
</ul>
<h2 id="问题解决"><a href="#问题解决" class="headerlink" title="问题解决"></a>问题解决</h2><h3 id="合并冲突问题"><a href="#合并冲突问题" class="headerlink" title="合并冲突问题"></a>合并冲突问题</h3><ul>
<li>如果执行推送时出现</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">! [rejected] master -&gt; master (fetch first) error: fail to push some refs<br></code></pre></td></tr></table></figure>

<ul>
<li>在执行推送前执行</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git pull --rebase origin master<br></code></pre></td></tr></table></figure>

<ul>
<li><p>将 README.md 拉到本地以解决此问题</p>
</li>
<li><p>如果当前本地仓库不是从远程仓库克隆，而是本地创建的仓库，并且仓库中存在文件，此时再从远程仓库中拉取文件的时候会报错</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">（fatal：refusing to merge unrelated histories）<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="如此拉取："><a href="#如此拉取：" class="headerlink" title="如此拉取："></a>如此拉取：</h5></li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs c">git pull origin master --allow-unrelated-histories<br></code></pre></td></tr></table></figure>

<ul>
<li>以解决此问题</li>
</ul>
<h2 id="2023-04-13-17-57"><a href="#2023-04-13-17-57" class="headerlink" title="2023 04.13 17:57"></a>2023 04.13 17:57</h2><h2 id="2023-04-26-23-52"><a href="#2023-04-26-23-52" class="headerlink" title="2023 04.26 23:52"></a>2023 04.26 23:52</h2><p>今天可算抽出时间，把用户中心-伙伴匹配系统的后端代码托管到gitte仓库上了，那就浅浅总结一下最简单无脑的一条龙推送流程吧：</p>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git init<br></code></pre></td></tr></table></figure>

<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git remote -v<br></code></pre></td></tr></table></figure>

<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git remote remove origin<br></code></pre></td></tr></table></figure>

<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git remote add origin 【仓库地址】<br></code></pre></td></tr></table></figure>

<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git add .<br></code></pre></td></tr></table></figure>

<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git commit -m &quot;提交信息&quot; .<br></code></pre></td></tr></table></figure>

<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git pull origin master / git pull origin master --allow-unrelated-histories<br></code></pre></td></tr></table></figure>

<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs markdown">git push origin master<br></code></pre></td></tr></table></figure>

<ul>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/u010784833/article/details/131305689">(77条消息) git撤销推送_git 取消推送_wxz470960225的博客-CSDN博客</a></li>
</ul>
<h2 id="远程推送问题"><a href="#远程推送问题" class="headerlink" title="远程推送问题"></a>远程推送问题</h2><h3 id="远程仓库未同步"><a href="#远程仓库未同步" class="headerlink" title="远程仓库未同步"></a>远程仓库未同步</h3>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/deng-2022/blog_2/categories/Git/" class="category-chain-item">Git</a>
  
  
    <span>></span>
    
  <a href="/deng-2022/blog_2/categories/Git/%E7%BB%8F%E9%AA%8C/" class="category-chain-item">经验</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/deng-2022/blog_2/tags/%E7%BB%8F%E9%AA%8C/">#经验</a>
      
        <a href="/deng-2022/blog_2/tags/Git/">#Git</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>入门指南：掌握Git的基本操作及进阶学习</div>
      <div>https://atomgit.com/deng-2022/blog_2/2023/03/17/入门指南：掌握Git的基本操作及进阶学习/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Memory</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年3月17日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年11月13日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/deng-2022/blog_2/2023/03/17/Memory%20%E7%94%A8%E6%88%B7%E4%B8%AD%E5%BF%83%E7%B3%BB%E7%BB%9F-%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="Memory 用户中心中心-开发文档">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Memory 用户中心中心-开发文档</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/deng-2022/blog_2/2023/03/15/%E6%B5%8B%E8%AF%95%E6%96%87%E6%A1%A3%EF%BC%9A%E5%8D%9A%E5%AE%A2%E5%88%9D%E4%BD%93%E9%AA%8C/" title="测试文档：博客初体验">
                        <span class="hidden-mobile">测试文档：博客初体验</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments">
      

    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>Memory | 个人文档站点</span> </a>
<i class="iconfont icon-love"></i> <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>配置指南 | Hexo Fluid 用户手册</span> </a>   
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      京ICP证123456号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/deng-2022/blog_2/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/deng-2022/blog_2/js/events.js" ></script>
<script  src="/deng-2022/blog_2/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>







  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/deng-2022/blog_2/js/local-search.js" ></script>

  <script defer src="/deng-2022/blog_2/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/deng-2022/blog_2/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
